<?php

class Jaxson
{	
	public static function error($title, $description)
	{
		$error['title']=$title;
		$error['description']=$description;
		$response['error']=$error;
		
		self::respond($response);
	}
	
	public static function success($val=false)
	{
		self::respond(true);
	}

	public static function respond($response)
	{
		die(self::encode($response));
	}
	
	public static function encode($multi)
	{
		return json_encode($multi);
	}
	
	public static function decode($multi)
	{
		return json_decode($multi);
	}
	
	public static function loadFeed($feedsDir)
	{
		if(!isset($_REQUEST['method']))
		Jaxson::error("No Method??","You must specify the method of the call");
		
		if(!is_dir($feedsDir))
		Jaxson::error("No Feeds Dir??","The specified Feeds Directory does not exist");
		
		$method = explode('.',$_REQUEST['method']);
		
		if(count($method)!=2)
		Jaxson::error("Invalid Method!!","You must specify the method with the Class.MethodName Syntax");
		
		if(!is_dir($feedsDir.'/'.$method[0]))
		Jaxson::error("Invalid Method!!","The specified Class does not exist");
		
		if(!is_file($feedsDir.'/'.$method[0].'/'.$method[1].'.php'))
		Jaxson::error("Invalid Method!!","The specified Method does not exist");
		
		require($feedsDir.'/'.$method[0].'/'.$method[1].'.php');
	}
}
